package tech.yiyehu.modules.bss.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import tech.yiyehu.modules.bss.entity.FoodEntity;
import tech.yiyehu.modules.bss.service.FoodService;
import tech.yiyehu.common.utils.PageUtils;
import tech.yiyehu.common.utils.R;



/**
 * 预约人
 *
 * @author yiyehu
 * @email 2681844336@qq.com
 * @date 2019-06-02 23:02:00
 */
@RestController
@Api(value="食物")
@RequestMapping("bss/food")
public class FoodController {
    @Autowired
    private FoodService foodService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("bss:food:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = foodService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("bss:food:info")
    public R info(@PathVariable("id") Long id){
			FoodEntity food = foodService.selectById(id);

        return R.ok().put("food", food);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("bss:food:save")
    public R save(@RequestBody FoodEntity food){
			foodService.insert(food);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @RequiresPermissions("bss:food:update")
    public R update(@RequestBody FoodEntity food){
			foodService.updateById(food);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("bss:food:delete")
    public R delete(@RequestBody Long[] ids){
			foodService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
